package org.yray.util;

import java.lang.reflect.Field;

public class ReflectionUtil {
    public static void setFieldValue(Object target, String[] fieldName, Object value) {
        try {
            Field field = target.getClass().getDeclaredField(fieldName[0]);
            field.setAccessible(true);
            if(fieldName.length==1)
            {

                field.set(target, value);
                return;
            }
            Object fieldObj = field.get(target);
            if(fieldObj==null)
            {
                fieldObj = field.getType().newInstance();
                field.set(target, fieldObj);
            }
            setFieldValue(fieldObj,new String[]{fieldName[1]},value);

        } catch (NoSuchFieldException | IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }
    }


}
